﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jiuyong
{
	//namespace ToolBox
	//{
	//	public static partial class Core
	//	{
	//		internal static void SelectPathDialog(Action<string> dialogBack, string initialDirectory = null)
	//		{
	//			//throw new NotImplementedException();
	//			var dlg = new OpenFileDialog();
	//			dlg.FileName = "选择文件夹";
	//			//dlg.Filter = "|.选择文件夹";
	//			dlg.CheckFileExists = false;
	//			dlg.CheckPathExists = true;
	//			dlg.InitialDirectory = initialDirectory;
	//			if (true == dlg.ShowDialog())
	//			{
	//				dialogBack(System.IO.Path.GetDirectoryName(dlg.FileName));
	//			}
	//		}
	//	}
	//}

	public static partial class ToolBoxExtention
	{
		internal static void ShowTextDialog(this System.Windows.Controls.Panel panel
			,
			Action<string> dialogBack
			,
			string defaultText = null
			,
			IEnumerable<string> otherTexts = null
			,
			string messageText = "输入字符串(_I)："
			)
		{
			if (null == panel)
			{
			}
			else
			{
				//ToolBox.Core.ShowTextDialog(panel);
			}
			//throw new NotImplementedException();
			var dlg = new InputStringWindow();
			dlg.ViewModel.InputString = defaultText;
			dlg.ViewModel.MessageText = messageText;
			if (null==otherTexts)
			{

			}
			else
			{
				foreach (var t in otherTexts)
				{
					dlg.ViewModel.OtherStrings.UnionWith(otherTexts);
				}
			}
			dlg.Closed += (b, c) =>
			{
				if (true == dlg.DialogResult)
				{
					//InputText = dlg.ViewModel.InputString;
					dialogBack(dlg.ViewModel.InputString);
					panel.Children.Remove(dlg);
				}
			};
			panel.Children.Add(dlg);
			dlg.Show();
		}
	}
}
